home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / General / ProNET / src / src / pronet-stop.c < prev    next >
C/C++ Source or Header  |  1997-01-26  |  3KB  |  112 lines

  1. /*
  2.     pronet-stop.c
  3.  
  4.     Dieses Programm wuselt in irgendwelchen obstrusen Datenstrukturen rum ;)=
  5.  
  6. */
  7.  
  8. #include <string.h>
  9.  
  10. #include <exec/execbase.h>
  11. #include <dos/dos.h>
  12. #include <dos/filehandler.h>
  13.  
  14. #include <proto/exec.h>
  15. #include <proto/dos.h>
  16.  
  17. void __chkabort(void) {}    /* Disable CTRL-C handling */
  18. ULONG __nocommandline = 0;
  19.  
  20. static char template[]="DEVICENAME,UNIT/K/N";
  21. static LONG array[2];
  22. static const char handlername[]="l:pronet-handler";
  23.  
  24. char versiontag[] = "$VER: pronet-stop 38.0 (26.1.97)";
  25.  
  26. static LONG stop_pronet_dev(struct DosList *dl)
  27. {
  28.     struct DosPacket *dospacket;
  29.     struct MsgPort *rp;
  30.     struct FileSysStartupMsg* fssm;
  31.     LONG err = 0;
  32.  
  33.     if(rp = CreateMsgPort()) {
  34.         if(dospacket = AllocDosObject(DOS_STDPKT, NULL)) {
  35.             dospacket->dp_Port = rp;
  36.             dospacket->dp_Type = ACTION_DIE;
  37.             PutMsg(dl->dol_Task, dospacket->dp_Link);
  38.             WaitPort(rp);
  39.             GetMsg(rp);
  40.  
  41.             FreeDosObject(DOS_STDPKT, dospacket);
  42.         }
  43.         else err=ERROR_NO_FREE_STORE;
  44.  
  45.         DeleteMsgPort(rp);
  46.     }
  47.     else err=ERROR_NO_FREE_STORE;
  48.  
  49.     return(err);
  50. }
  51.  
  52. int main()
  53. {
  54.     struct RDArgs *rdargs;
  55.     struct DosList *dl;
  56.     int RC = 20;
  57.  
  58.     if(rdargs = ReadArgs(template,&array[0],NULL)) {
  59.         if(array[0]) {
  60.             dl = LockDosList(LDF_DEVICES|LDF_READ);
  61.             dl = FindDosEntry(dl, (char*)array[0], LDF_DEVICES);
  62.             UnLockDosList(LDF_DEVICES|LDF_READ);
  63.     
  64.             if(dl) {
  65.                 if(((char*)BADDR(dl->dol_misc.dol_handler.dol_Handler))[0] == sizeof(handlername)-1
  66.                         && !strcmp(BADDR(dl->dol_misc.dol_handler.dol_Handler)+1, handlername)) {
  67.                     LONG err = stop_pronet_dev(dl);
  68.                     if(err)
  69.                         PrintFault(err, NULL);
  70.                     else
  71.                         RC = 0;
  72.                 }
  73.                 else
  74.                     Printf("Device `%s:' is not a ProNET device.\n",array[0]);
  75.             }
  76.             else
  77.                 Printf("Device `%s:' not found on this machine.\n",array[0]);
  78.         }    
  79.         else if(array[1]) {
  80.             RC = 0;
  81.  
  82.             do {
  83.                 dl = LockDosList(LDF_DEVICES|LDF_READ);
  84.                 while((dl = NextDosEntry(dl, LDF_DEVICES))
  85.                 && !(((char*)BADDR(dl->dol_misc.dol_handler.dol_Handler))[0] == sizeof(handlername)-1
  86.                     && !strcmp(BADDR(dl->dol_misc.dol_handler.dol_Handler)+1, handlername)
  87.                     && ((struct FileSysStartupMsg*)BADDR(dl->dol_misc.dol_handler.dol_Startup))->fssm_Unit == *(LONG*)array[1]));
  88.                 UnLockDosList(LDF_DEVICES|LDF_READ);
  89.                 if(dl) {            
  90.                     LONG err;
  91.  
  92.                     Printf("Stopping %s:...\n", 1+(ULONG)BADDR(dl->dol_Name));
  93.  
  94.                     if(err = stop_pronet_dev(dl)) {
  95.                         PrintFault(err, NULL);
  96.                         RC = 20;
  97.                         break;
  98.                     }
  99.                 }
  100.             } while(dl);
  101.         }
  102.         else
  103.             Printf("Need device name or unit number!\n");
  104.  
  105.         FreeArgs(rdargs);
  106.     }
  107.     else
  108.         PrintFault(IoErr(), NULL);
  109.  
  110.     return(RC);
  111. }
  112.